package memento.example;

import lombok.Data;

/**
 *  角色类
 */
@Data
public class Role {
    // 生命力
    private int vit;
    // 攻击力
    private int atk;
    // 防御力
    private int def;

    // 保存角色状态
    public RoleStateMemento saveState () {
        return new RoleStateMemento(vit, atk, def);
    }

    // 恢复角色状态
    public void recoveryState (RoleStateMemento memento) {
        this.vit = memento.getVit();
        this.atk = memento.getAtk();
        this.def = memento.getDef();
    }

    // 战斗后扣血
    public void fight(){
        this.vit = 0;
        this.atk = 0;
        this.def = 0;
    }

    @Override
    public String toString() {
        return "Role{" +
                "vit=" + vit +
                ", atk=" + atk +
                ", def=" + def +
                '}';
    }
}
